<?php
class Listing_Form_PostAnAddJobForm extends Listing_Form_PostAnAddForm
{
    private $_preview_link = '';

    private $_category;
    private $_adid;
    private $_listing;

    protected $elementButtonDecorators = array(
        'ViewHelper',
        'Errors',
    );

    protected $elementDecorators = array(
        'ViewHelper',
        //'Errors',
    );

    protected $formDecorators = array(
            'PrepareElements',
            array('ViewScript', array('viewScript' => 'index/customization/job-post-an-ad.phtml'))
    );

    protected $subFormDecorators = array(
        'FormElements',
        array('Description', array('placement' => 'prepend')),
        'fieldset',
    );

    protected $spanDecorators = array(
        'ViewHelper',
        'Errors',
        array('Label', array('placement' => 'prepend')),
        array(array('row' => 'HtmlTag'), array('tag' => 'span')),
    );

    protected $displayGroupDecorators = array(
        'FormElements',
        array('HtmlTag', array('tag' => 'p', 'class' => 'price radio text')),
        array('Description', array('placement' => 'prepend', 'tag' => 'label')),
    );

    protected $elementCheckBoxDecorators = array(
        'ViewHelper',
        'Errors',
        array('Label', array('placement' => 'APPEND')),
    );
    
    protected $elementMultiCheckBoxDecorators = array(
        'ViewHelper',
        'Errors',
    );

    protected $elementSelectDecorators = array(
        'ViewHelper',
        'Errors',
        array('Label', array()),
        array(array('row' => 'HtmlTag'), array('class'=>'select')),
    );
    
    protected $elementSelectDecorators1 = array(
        'ViewHelper',
        'Errors',
        array('Label', array()),
        array(array('row' => 'HtmlTag'), array('class'=>'select1')),
    );

    public function __construct($options = array())
    {dump($options);
        $this->_preview_link = !empty($options['preview_link']) ? $options['preview_link'] : '';
        $this->_category = !empty($options['category']) ? $options['category'] : array();
        $this->_adid = !empty($options['adid']) ? $options['adid'] : array();
        $this->_listing = !empty($options['listing']) ? $options['listing'] : new StdClass();
        parent::__construct();
    }
    
    public function isValid($post = array())
    {
        $test1 = parent::isValid($post);
        $test2 = true;
   
        //Price
        if (empty($_POST['salary']) && empty($_POST['salary_hour'])) {
        	$this->getElement('salary')->addError('请在下拉菜单选择一个选项，不能为空');
        	$this->getElement('salary_hour')->addError('请在下拉菜单选择一个选项，不能为空');
        	$test2 = false;
        }

        //Check the two validations
        if ($test1 & $test2){
            return true;
        }
        else {
            return false;
        }
    }
    
    public function init()
    {
        parent::init();
        $element = new Zend_Form_Element_Hidden('adid');
        $element->setValue((string) $this->_adid);
        $element->setDecorators(array(
                'ViewHelper'
            )
        );
        $this->addElement($element);
        
        $i = 0;
        foreach($this->_category  as $cat) {
            $i++;
            $element = new Zend_Form_Element_Hidden('category_link'.$i);
            $element->setValue((string) $cat->_id);
            $element->setDecorators(array(
                    'ViewHelper'
                )
            );
            $this->addElement($element);
        }
        $cat_str = '<ul>';
        foreach ($this->_category as $cat_id) {
            $cat_str .= '<li>';
            $tmp = array();            
            $category = Model_Category::find($cat_id->_id);
            foreach ($category->getParentTree() as $cat) {
                $tmp[] = $cat->name;
            }
            $cat_str .= implode(' > ', $tmp);
            $cat_str .= '</li>';
        }
        $cat_str .= '</ul>';
        $this->setDescription($cat_str);

        //Title
        $this->addElement('text', 'tl_en', array(
            'validators' => array(
                array('NotEmpty', true, array('messages' => '星号栏必须填写')),
            ),
            'decorators' => $this->elementDecorators,
            'required'   => true,
        ));

        //Company name
        $this->addElement('text', 'cn_en', array(
            'validators' => array(
                array('NotEmpty', true, array('messages' => '星号栏必须填写')),
            ),
            'decorators' => $this->elementDecorators,
            'required'   => true,
        ));        
        
        // Employment Type
        /*$this->addElement('multiCheckbox', 'employmenttype', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('NotEmpty', true, array('messages' => 'This information is required')),
            ),
            'decorators'   => array(
                'ViewHelper',
                'Errors',
                array('Label', array()),
            ),
            'multiOptions' => Model_Listing_Job::getEmploymentTypePostAd(),
            'required'     => true,
        ));*/
        $this->addElement('radio', 'employmenttype', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
            	array('NotEmpty', true, array('messages' => '请在下拉菜单选择一个选项，不能为空')),
                'Int'
            ),
            'multiOptions' => Model_Listing_Job::getEmploymentTypePostAd(),
            'separator' => '',
            'value' => '1',
            'disableLoadDefaultDecorators' => true,
            'decorators' => $this->elementDecorators,
            'required'   => true,
        ));
        
        /*/ Job Location
        $this->addElement('multiCheckbox', 'joblocation', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('NotEmpty', true, array('messages' => 'This information is required')),
            ),
            'decorators'   => array(
                'ViewHelper',
                'Errors',
                array('Label', array()),
            ),
            'multiOptions' => Model_Listing_Job::getJobLocationPostAd(),
            'required'     => false,
        ));*/
        
        // Salary
        /*$this->addElement('text', 'salary', array(
            'validators' => array(
                array('NotEmpty', true, array('messages' => 'This information is required')),
                array('Float', true, array('messages' => 'Only numbers are allowed')),
            ),
            'decorators' => array('ViewHelper'),
            'required'   => false,
        ));*/
        $this->addElement('select', 'salary', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('NotEmpty', true, array('messages' => '请在下拉菜单选择一个选项，不能为空')),
            ),
            'decorators'   => array(
                'ViewHelper',
                //'Errors',
                array('Label', array()),
            ),
            'multiOptions' => Model_Listing_Job::getSalaryPostAd(),
            'required'     => false,
        ));
        
        // Salary
        /*$this->addElement('text', 'salary_hour', array(
            'validators' => array(
                array('NotEmpty', true, array('messages' => 'This information is required')),
                array('Float', true, array('messages' => 'Only numbers are allowed')),
            ),
            'decorators' => array('ViewHelper'),
            'required'   => false,
        ));*/
        $this->addElement('select', 'salary_hour', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('NotEmpty', true, array('messages' => '请在下拉菜单选择一个选项，不能为空')),
            ),
            'decorators'   => array(
                'ViewHelper',
                //'Errors',
                array('Label', array()),
            ),
            'multiOptions' => Model_Listing_Job::getSalaryHourPostAd(),
            'required'     => false,
        ));
        
        // Career Level
        /*$this->addElement('multiCheckbox', 'careerlevel', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('NotEmpty', true, array('messages' => 'This information is required')),
            ),
            'decorators'   => array(
                'ViewHelper',
                'Errors',
                array('Label', array()),
            ),
            'multiOptions' => Model_Listing_Job::getCareerLevelPostAd(),
            'required'     => false,
        ));*/
        
        // Education Level
        $this->addElement('select', 'educationlevel', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('NotEmpty', true, array('messages' => '请在下拉菜单选择一个选项，不能为空')),
            ),
            'decorators'   => $this->elementDecorators,
            'multiOptions' => Model_Listing_Job::getEducationPostAd(),
            'required'     => true,
        ));
        
        // Years of Experience
        $this->addElement('select', 'yearexperience', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('NotEmpty', true, array('messages' => '请在下拉菜单选择一个选项，不能为空')),
                //array('int', true, array('messages' => 'Only numbers are allowed')),
            ),
            'decorators'   => $this->elementDecorators,
            'multiOptions' => Model_Listing_Job::getYearExperiencePostAd(),
            'required'     => true,
        ));
        
        /*/ Fresh Graduate
        $this->addElement('multiCheckbox', 'freshgraduate', array(
            'validators' => array(
                //'EmailAddress',
            ),
            'multioptions' => array(1 => 'Fresh graduate will be also considered'),
            'disableLoadDefaultDecorators' => true,
            'decorators' => array(
                            'ViewHelper',
                            'Errors',
            ),
            'required'   => false,
        ));
        
        // Company Benefits
        $this->addElement('multiCheckbox', 'companybenefits', array(
            'validators' => array(
                //'EmailAddress',
            ),
            'decorators'   => $this->elementMultiCheckBoxDecorators,
            'multiOptions' => Model_Listing_Job::getCompanyBenefitsPostAd(),
            'required'     => false,
        ));


        // Add more
        $this->addElement('hidden', 'add_more_checkbox', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
            ),
            'disableLoadDefaultDecorators' => true,
            'decorators' => array(
                'ViewHelper',
                'Errors',
                array(array('data' => 'HtmlTag'), array('style' => 'display:none')),
            ),
            'value'   => 1,
            'required'   => false,
        ));
        
        // Resident Status
        $this->addElement('multiCheckbox', 'residentstatus', array(
            'filters'    => array('StringTrim'),
            'decorators'   => array(
                'ViewHelper',
                'Errors',
                array('Label', array()),
            ),
            'multiOptions' => Model_Listing_Job::getResidentStatusPostAd(),
            'required'     => false,
        ));*/
        
        /**********************************************************
         *                          LOCATION
         *********************************************************/
        $areas = Model_Location::getAreaL1PostAd();
        if (empty($_POST['area_l1'])) {
            $selected_area = 0;
            if (!empty($this->_listing)) {
                $selected_area = '';
                if (empty($selected_area)) {
                    $loc = $this->_listing->area_l2;
                    if (!empty($loc)) {
                        $selected_area = (string)$loc->getParent()->_id;
                    }
                }                   
            }
        }
        else {
            $selected_area = $_POST['area_l1'];
        }
        if (empty($selected_area)) {
            reset($areas);
            $selected_area = key($areas);
        }        
        $this->addElement('select', 'area_l1', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('NotEmpty', true, array('messages' => '请在下拉菜单选择一个选项，不能为空')),
            ),
            'multiOptions' => $areas,
            'disableLoadDefaultDecorators' => true,
            'decorators' => $this->elementDecorators,
            'required'   => true,
        ));

        //District
        $this->addElement('select', 'area_l2', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
                array('NotEmpty', true, array('messages' => '请在下拉菜单选择一个选项，不能为空')),
            ),
            'multiOptions' => Model_Location::getAreaL2PostAd($selected_area),
            'disableLoadDefaultDecorators' => true,
            'decorators' => $this->elementDecorators,
            'required'   => false,
        ));
        //$this->getElement('area_l2')->setOptions(array('disabled'=>'disabled'));
        
        //location flag
        $this->addElement('radio', 'loc_flag', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
                //'Int'
            ),
            'multiOptions' => array(
                'chi' => '中国+香港+澳门',
                'mchi' => '中国大陆',
            ),
            'separator' => '',
            //'value' => '0',
            'disableLoadDefaultDecorators' => true,
            'decorators' => $this->elementDecorators,
            'required'   => false,
        ));
        
        
        //Description
        $this->addElement('textarea', 'cs_en', array(
            'filters'    => array('StringTrim'),
            'validators' => array(
				array('NotEmpty', true, array('messages' => '星号栏必须填写')),
            ),
            'decorators' => $this->elementDecorators,
            'rows'=>'',
            'required'   => true,
        ));
        
        $this->addElement('text', 'tag', array(
            'validators' => array(
                //array('NotEmpty', true, array('messages' => 'This information is required')),                
            ),
            'decorators' => $this->elementDecorators,
            //'decorators' => array_merge($this->elementDecorators, array(array(array('row' => 'HtmlTag'), array('tag' => 'p', 'class' => 'title text')))),
            'required'   => false,
            'label'      => 'Tag:',
        ));
        
        $this->addElement('text', 'remark', array(
            'validators' => array(
                //array('NotEmpty', true, array('messages' => 'This information is required')),                
            ),
            'decorators' => $this->elementDecorators,
            //'decorators' => array_merge($this->elementDecorators, array(array(array('row' => 'HtmlTag'), array('tag' => 'p', 'class' => 'title text')))),
            'required'   => false,
            'label'      => 'Remark:',
        ));
        
        $this->addElement('text', 'c_name', array(
            'validators' => array(
                //array('NotEmpty', true, array('messages' => 'This information is required')),                
            ),
            'decorators' => $this->elementDecorators,
            //'decorators' => array_merge($this->elementDecorators, array(array(array('row' => 'HtmlTag'), array('tag' => 'p', 'class' => 'title text')))),
            'required'   => false,
            'label'      => 'Contact Name:',
        ));
        
        /*$this->addElement('checkbox', 'agent', array(
            'filters'    => array('StringTrim', 'StringToLower'),
            'validators' => array(
            ),
            'disableLoadDefaultDecorators' => true,
            'decorators' => $this->elementDecorators,
            'required'   => false,
        ));*/
        
        $this->addElement('text', 'c_tel', array(
            'validators' => array(
                //array('NotEmpty', true, array('messages' => 'This information is required')),                
            ),
            'decorators' => $this->elementDecorators,
            //'decorators' => array_merge($this->elementDecorators, array(array(array('row' => 'HtmlTag'), array('tag' => 'p', 'class' => 'title text')))),
            'required'   => false,
            'label'      => 'Contact Tel:',
        ));
        
        $this->addElement('text', 'c_msn', array(
            'validators' => array(
                //array('NotEmpty', true, array('messages' => 'This information is required')),                
            ),
            'decorators' => $this->elementDecorators,
            //'decorators' => array_merge($this->elementDecorators, array(array(array('row' => 'HtmlTag'), array('tag' => 'p', 'class' => 'title text')))),
            'required'   => false,
            'label'      => 'MSN / QQ:',
        ));
        
        $this->addElement('button', 'validate', array(
            'required'    => false,
            'ignore'      => true,
            'type'        => 'submit',
            'label'       => 'Post your ad',
            'decorators'  => array_merge($this->elementButtonDecorators, array(array(array('row' => 'HtmlTag'), array('tag' => 'p', 'class' => 'button_em')))),
        ));

        $this->addElement('button', 'preview', array(
            'required'    => false,
            'ignore'      => true,
            'type'        => 'button',
            'label'       => 'Preview',
            'decorators'  => array_merge($this->elementButtonDecorators, array(array(array('row' => 'HtmlTag'), array('tag' => 'p', 'class' => 'preview button')))),
        ));


        $opt = $this->getDecorator('ViewScript')->getOptions();
        $opt['category'] = $this->_category;
        $opt['adid'] = $this->_adid;
        $opt['listing'] = $this->_listing;
        $opt['preview_link'] = $this->_preview_link;

        $this->getDecorator('ViewScript')->setOptions($opt);

    }

    public function save($preview = false)
    {
        if (empty($this->_adid)) {
            $ad = new Model_Listing_Regular();
        } else {
            $ad = Model_Listing_Preview::find(new MongoId($this->_adid));
        }

        if (Zend_Registry::isRegistered('loggedin_user')) {
            $user = Zend_Registry::get('loggedin_user');
            if ($user->role == Model_User::ROLE_ADMIN) {
                if(empty($ad->us)) {
                    $ad->user        = $user->_id;    
                }
            } else {
                $ad->user        = $user->_id;
            }
            if (empty($this->status)) {
                $ad->status = Model_Listing::STATUS_PUBLISHED;
            }
        } else {
            $ad->status = 6;
        }
		
        //Requiered Attributs
        //$ad->tl_en          = (string)$_POST['tl_en'];
		
		$classname = Model_Listing::getInstanceClassname((array)$this->_listing->ca);
		$translateFields = $classname::getTranslationFormField();
		// echo $_POST['tl_en']; echo '<br>';
		// echo $_POST['cn_en']; echo '<br>';
		// echo $_POST['cs_en'];
		// print_r($translateFields);
		// exit;
		// $this->translate($ad, $translateFields, $classname);
		
		if (Zend_Registry::get('current_language') == 'en'){
			if ($ad->ad_type == -1) { 
				$ad->ad_type = Model_Listing::ORIGINAL_LANGUAGE_EN;
			}
			$ft = 'en';
			$tt = 'zh-TW';
			
			foreach($translateFields as $v => $r){
				$ad->{$v} = $this->getValue($v);
				
				if($v == 'cn_en'){
					if (empty($ad->{str_replace('en','tc', $v)})){
						$ad->{str_replace('en','tc', $v)} = $this->getValue($v);
					}
				} else {
					if (empty($ad->{str_replace('en','tc', $v)})){
						$ad->{str_replace('en','tc', $v)} = Ac_Translation::execute($this->getValue($v), $tt, $ft);
					}
				}
				
			}

		} else {
			if ($ad->ad_type == -1) {
				$ad->ad_type = Model_Listing::ORIGINAL_LANGUAGE_TC;
			}
			$ft = 'zh-TW';
			$tt = 'en';		
			
			foreach($translateFields as $v => $r){
				$ad->{str_replace('en','tc', $v)} = $this->getValue($v);
				
				if($v == 'cn_en'){
					if (empty($ad->{$v})){
						$ad->{$v} = $this->getValue($v);
					}
				} else {
					if (empty($ad->{$v})){
						$ad->{$v} = Ac_Translation::execute($this->getValue($v), $tt, $ft);
					}
				}
				

			}
		

		}

       // $ad->cn_en   = $_POST['cn_en'];
        $ad->employmenttype = $_POST['employmenttype'];
        $ad->salary         = $_POST['salary'];
        $ad->salary_hour    = $_POST['salary_hour'];
        //$key = array_search(-5, $_POST['residentstatus']);
        //if ($key !== false) {unset($_POST['residentstatus'][$key]);}
        //$ad->residentstatus = $_POST['residentstatus'];
        //$ad->careerlevel    = $_POST['careerlevel'];
        //$ad->joblocation    = $_POST['joblocation'];
        //$ad->description    = (string)$_POST['description'];
        
        //
        $ad->area_l1                   = new MongoId($POST['area_l1']);
        if ((string)$_POST['area_l1'] == ONLINE_ONLY_AREA) {
            $ad->area_l2 = new MongoId(ONLINE_ONLY_AREA);
        }
        elseif((string)$this->getValue('area_l1') == ENTIRE_CITY) {
            $ad->area_l2 = new MongoId(ENTIRE_CITY);
        }
        else {
            $ad->area_l2 = new MongoId($_POST['area_l2']);
        }

        //Optional Attributs
        if (!empty($_POST['educationlevel']))    {$ad->education          = (int)$_POST['educationlevel'];}
        if (!empty($_POST['yearexperience']))    {$ad->yearexperience     = (int)$_POST['yearexperience'];}
        //if (!empty($_POST['freshgraduate']))     {$ad->freshgraduate      = (int)$_POST['freshgraduate'][0];}
        //if (!empty($_POST['companybenefits']))   {$ad->companybenefits    = (array)$_POST['companybenefits'];}
        $ad->tl_sc 			= (string)$this->getValue('tl_en');
        $ad->cs_sc 			= (string)$this->getValue('cs_en');
        $ad->st_sc 			= (string)$this->getValue('st_en');
        //$ad->tag 			= (string)$this->getValue('tag');
		if (!empty($POST['tag']))         {$ad->tags         = array_values(explode(',',$_POST['tag']));}
        $ad->rmrk 			= (string)$this->getValue('remark');
        $ad->c_name 		= (string)$this->getValue('c_name');
        $ad->c_tel 			= (string)$this->getValue('c_tel');
        $ad->c_msn 			= (string)$this->getValue('c_msn');
        $ad->loc_flag = (string)$this->getValue('loc_flag');
        //$ad->agent = (string)$this->getValue('agent');
        
        foreach ((array) $_REQUEST['category'] as $cat) {
            $tmp = new MongoId($cat);
            $ad->addCategory($tmp);
        }

        $this->continueFillup();
        if (!$preview) {
            $ad = Model_Listing_Preview::saveAsListing($ad);
            Model_Listing_Preview::remove(array('_id' => $ad->_id));
        } else {
            //$ad = Model_Listing_Preview::convertFromListing($ad);
            $ad->forceSave();
        }
        return $ad;
    }
	
    protected function continueFillup()
    {

    }

    public function populate(array $arr)
    {
        // if (empty($arr['title'])) {
            // $this->getElement('title')->setValue($this->_listing->title);
        // }
        if (Zend_Registry::get('current_language') == 'en'){
			$ft = 'en';
			$tt = 'zh-TW';
			
            $this->getElement('tl_en')->setValue($this->_listing->tl_en);
			$this->getElement('cn_en')->setValue($this->_listing->cn_en);
			$this->getElement('cs_en')->setValue($this->_listing->cs_en);
			
			
		} else {
			$ft = 'zh-TW';
			$tt = 'en';
			
			$this->getElement('tl_en')->setValue($this->_listing->tl_sc);
			$this->getElement('cn_en')->setValue($this->_listing->cn_sc);
			$this->getElement('cs_en')->setValue($this->_listing->cs_sc);
			
		}

        //$this->getElement('tl_en')->setValue($this->_listing->tl_en);
        
        //$this->getElement('cn_en')->setValue($this->_listing->cn_en);

        if (empty($arr['employmenttype'])) {
            $this->getElement('employmenttype')->setValue($this->_listing->employmenttype);
        }
        if (empty($arr['salary'])) {
            $this->getElement('salary')->setValue($this->_listing->salary);
        }
        if (empty($arr['salary_hour'])) {
            $this->getElement('salary_hour')->setValue($this->_listing->salary_hour);
        }
        /*if (empty($arr['joblocation'])) {
            $this->getElement('joblocation')->setValue($this->_listing->joblocation);
        }
        
        if (empty($arr['residentstatus'])) {
            if (empty($this->_listing->residentstatus)) {
                $this->getElement('residentstatus')->setValue(-2);
            } else {
                $this->getElement('residentstatus')->setValue($this->_listing->residentstatus);
            }
        }
        if (empty($arr['careerlevel'])) {
            $this->getElement('careerlevel')->setValue($this->_listing->careerlevel);
        }*/

        /* if (empty($arr['cs_en'])) {
            $this->getElement('cs_en')->setValue($this->_listing->cs_en);
        } */
        
        //Area
        if (empty($arr['area_l1'])) {
                $selected_area = '';
                if (empty($selected_area)) {
                    $loc = $this->_listing->area_l2;
                    if (!empty($loc)) {
                        $selected_area = (string)$loc->getParent()->_id;
                    }
                }            
            $this->getElement('area_l1')->setValue((string)$selected_area);
        }
        //District
        if (empty($arr['area_l2'])) {
            if (isset($this->_listing->area_l2->_id)) {
                $this->getElement('area_l2')->setValue((string)$this->_listing->area_l2->_id);
            }
        }

        if (empty($arr['education'])) {
            $this->getElement('educationlevel')->setValue($this->_listing->education);
        }
        if (empty($arr['yearexperience'])) {
            $this->getElement('yearexperience')->setValue($this->_listing->yearexperience);
        }
        /*/agent
        if (empty($arr['agent'])) {
            $this->getElement('agent')->setValue((string)$this->_listing->agent);
        }*/
        /*if (empty($arr['freshgraduate'])) {
            $this->getElement('freshgraduate')->setValue($this->_listing->freshgraduate);
        }
        if (empty($arr['companybenefits'])) {
            $this->getElement('companybenefits')->setValue($this->_listing->companybenefits);
        }*/

		if (empty($arr['tag'])) {
        	if(!empty($this->_listing->tags)){
				$this->getElement('tag')->setValue(implode(',', $this->_listing->tags));
			}            
        }
        
        if (empty($arr['remark'])) {
            $this->getElement('remark')->setValue((string)$this->_listing->remark);
        }
        
        if (empty($arr['c_name'])) {
            $this->getElement('c_name')->setValue((string)$this->_listing->c_name);
        }
        
        if (empty($arr['c_tel'])) {
            $this->getElement('c_tel')->setValue((string)$this->_listing->c_tel);
        }
        
        if (empty($arr['c_msn'])) {
            $this->getElement('c_msn')->setValue((string)$this->_listing->c_msn);
        }
    }
	
	public function __toString()
    {
        $str = '
            $j("#area_l1").change(function (event) {                
                event.stopImmediatePropagation();
                $j.get("/search/get-attribute", { c:"area", f:"area_l2_postad", id: $j("#area_l1").val() },
                    function(data) {
                        $j("#area_l2").empty();
                        $j.each(data, function (index, value) {
                            $(document.createElement("option"))
                                .html(value)
                                .attr("value", index)
                                .appendTo($("#area_l2"));
                        });
                         //Entire City
					    if ($j("#area_l1").val() == "4eeae63be62d6c5978000000" || $j("#area_l1").val() == "4eeeeeeeeeeeeeeeeeeeeeee" || $j("#area_l1").val() == "4aaaaaaaaaaaaaaaaaaaaaaa") {
					        $j("#area_l2").hide();
					        $j("#st_en").hide();
					    }
					    else {
					        $j("#area_l2").show();
					        $j("#st_en").show();
					    }
                    });
           });
		   
        ';
		
		$str2 = '
			$j("tl_tc_back").click(function(event) {
			alert("test");
   
			});
		
		';
        $this->view->JQuery()->addJavascript($str);
		$this->view->JQuery()->addJavascript($str2);
        return parent::__toString();
    }
}
